package com.wb.mas.ui.bank;

import android.app.Application;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableList;

import com.wb.mas.BR;
import com.wb.mas.R;
import com.wb.mas.data.DemoRepository;
import com.wb.mas.entity.BankResponse;
import com.wb.mas.entity.GuideEntity;
import com.wb.mas.entity.OrderEntity;
import com.wb.mas.ui.base.viewmodel.ToolbarViewModel;
import com.wb.mas.ui.order.OrderActivity;
import com.wb.mas.ui.order.OrderItemViewModel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;
import me.goldze.mvvmhabit.utils.ToastUtils;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

/**
 * Copyright (C) 2018,
 * OrderViewModel
 * <p>
 * Description
 * 银行卡
 *
 * @author mwl
 * @version 1.0
 * <p>
 * Ver 1.0, 2019-04-30, mwl, Create file
 */
public class BankViewModel extends ToolbarViewModel {

    //银行卡名称
    public ObservableField<String> bankName = new ObservableField<>();

    public ObservableField<String> bankCard = new ObservableField<>();

    public ObservableField<String> realName = new ObservableField<>();

    public BankViewModel(@NonNull Application application, DemoRepository model) {
        super(application, model);
        init();
    }

    private void init() {
        setTitleText(getString(R.string.bank_title));
        setRightIconVisible(View.GONE);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        getBank();
    }

    private void getBank() {
        showDialog();
        Map<String, Object> maps = new HashMap<>();
        List<String> stringList = new ArrayList<>();
        stringList.add("bank_info_code");
        maps.put("pageCodes", stringList);
        addSubscribe(model.getBankDetail(maps)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<BankResponse>() {
                    @Override
                    public void accept(BankResponse bankResponse) throws Exception {
                        dismissDialog();
                        if (bankResponse != null && bankResponse.getData() != null) {
                            bankCard.set(bankResponse.getData().bankCard);
                            bankName.set(bankResponse.getData().bankValue);
                            realName.set(bankResponse.getData().realName);
                        }

                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        dismissDialog();
                        throwable.printStackTrace();
                        ToastUtils.showShort(throwable.getMessage());
                    }
                }));


    }

}
